// class_sddamd.cpp

#include "auxlib.h"
#include <iostream>
using namespace std;
#include "class_sddamd.h"

void fillMatrixSDVector(SDVector & v,double d)
{
	for (unsigned i=0 ; i < v.m_row ; i++) {
		for (unsigned j=0 ; j < v.m_col ; j++) {
			v(i,j) = d; 
		}
	}
}

void addToMatrixSDVector(SDVector & v,double d)
{
	for (unsigned i=0 ; i < v.m_row ; i++) {
		for (unsigned j=0 ; j < v.m_col ; j++) {
			v(i,j) += d; 
		}
	}
}

void class_sddamd(int size)
{
	cout << "=== class_sddamd, size=" << size << endl;
	double eps = 1e-8;
	MyClock clk;
	double duration_sec;
	clk.markTime();
	// code to test begin (1)
	int row = size, col = size;
	SDVector sdVector;
	sdVector.alloc(row,col);
	fillMatrixSDVector(sdVector,1.1);
	duration_sec = clk.getDiffTime();
	cout << "alloc & fill matrix=" << duration_sec << " sec" << endl;
	// code to test begin (2)
	clk.markTime();
	addToMatrixSDVector(sdVector,2.2);
	duration_sec = clk.getDiffTime();
	cout << "addToMatrix=" << duration_sec << " sec" << endl;
	// code to test end (2)

	// confirm that add was done
	myAssert(nearEqual(sdVector(2,3),3.3,eps));
}
